import React, { Component } from "react";
import { inject, observer } from "mobx-react";

@inject("appleBasket")
@observer
class AppleList extends Component {
  render() {
    const { appleBasket } = this.props
    const { existApples, eatApple } = appleBasket
    return (
      <div className="appleList">
        {
          (existApples || []).length > 0
            ? existApples.map(apple => (
              <div className="appleItem" key={apple.id}>
                <div className="apple">
                  <img src={require('../images/apple.png')} alt="" />
                </div>
                <div className="info">
                  <div className="name">红苹果 - {apple.id}号</div>
                  <div className="weight">{apple.weight}克</div>
                </div>
                <div className="btn-div">
                  <button onClick={() => eatApple(apple.id)}>吃掉</button>
                </div>
              </div>
            ))
            : <div className="empty-tip" key="empty">苹果篮子空空如也</div>
        }
      </div>
    );
  }
}

export default AppleList;
